class Array
  # Assert that the elements in the Array are of the given types
  #
  # @param types [*Class] list of Classes to match against the elements
  # @return [true] if all elements are of the proper type
  # @return [false] otherwise
  # @raise ArgumentError if the number of arguments does not match the length of the Array
  # @raise ArgumentError if an element does not match the require type in the arguments
  def assert_types(*types)
    if types.length != self.length
      raise ArgumentError, "Number of arguments must match length of Array"
    end

    each_index do |i|
      unless self[i].is_a?(types[i])
        raise ArgumentError, "Value at index %s expected to be a %s"%[i, types[i]]
      end
    end

    true
  end
end
